package com.site.dao;

import com.site.common.DbHelper;
import com.site.entity.ConfigEntity;

import java.sql.ResultSet;
import java.sql.SQLException;

public class ConfigDao extends DbHelper {

    public ConfigDao() throws ClassNotFoundException, SQLException {

    }

    /**
     * 配置信息（一条）
     * @return
     * @throws SQLException
     */
    public ConfigEntity getConfig() throws SQLException {
        String sql="select * from tbConfig limit 1";
        ResultSet rs=query(sql); //这是一个结果集

        ConfigEntity e = getEntity(rs);

        close();

        return e;
    }

    /**
     * 转换实体
     * @param rs
     * @return
     * @throws SQLException
     */
    private ConfigEntity getEntity(ResultSet rs) throws SQLException {
        if(rs.next()){
            ConfigEntity entity=new ConfigEntity();

            entity.setAdress(rs.getString("adress"));
            entity.setEmail(rs.getString("email"));
            entity.setIcp(rs.getString("icp"));
            entity.setLogo(rs.getString("logo"));
            entity.setPhone(rs.getString("phone"));
            entity.setRemark(rs.getString("remark"));
            entity.setRights(rs.getString("rights"));
            entity.setTitle(rs.getString("title"));
            entity.setWechatlogo(rs.getString("Wechatlogo"));
            entity.setQQlogo(rs.getString("QQlogo"));
            entity.setPageIcon(rs.getString("PageIcon"));

            return  entity;
        }

        return  null;
    }
}
